package com.example.onlineeducation.ui.common

import android.content.Context
import android.content.Intent
import android.view.View
import com.example.onlineeducation.base.BaseActivity
import com.example.onlineeducation.databinding.CommonImgZoomActivityBinding

import com.yc.jetpacklib.extension.ycIsEmpty
import com.yc.jetpacklib.extension.ycLoadImageNet
import com.yc.jetpacklib.utils.showSingleBtnDialog
import com.yc.jetpacklib.widget.dialog.YcCommonDialog

/**
 * SimpleDes:
 * Creator: Sindi
 * Date: 2021-10-22
 * UseDes:
 */
class CommonImgZoomActivity : BaseActivity<CommonImgZoomActivityBinding>(CommonImgZoomActivityBinding::inflate) {

    companion object {
        private const val IMG_FILE_URL = "img_file_url"
        fun newInstance(context: Context, fileUrl: String?) {
            Intent(context, CommonImgZoomActivity::class.java).apply {
                putExtra(IMG_FILE_URL, fileUrl)
                context.startActivity(this)
            }
        }
    }


    override fun CommonImgZoomActivityBinding.initView() {
        val fileUrl = intent.getStringExtra(IMG_FILE_URL)
        if (fileUrl.ycIsEmpty()) {
            showSingleBtnDialog(mDialog, "图片链接不存在") { finish() }
        } else {
            photoView.apply {
                enable()
                this.ycLoadImageNet(fileUrl)
                setOnClickListener {
                    finish()
                }
            }
        }
    }
}